package com.cvte.shop.service.impl;

import com.cvte.csb.core.interfaces.vo.RestResponse;
import com.cvte.csb.web.rest.ResponseFactory;
import com.cvte.shop.constants.UniversalResultFieldsConstants;
import com.cvte.shop.entity.UniversalResultFields;
import com.cvte.shop.entity.dto.FieldDTO;
import com.cvte.shop.enums.RestResponceEnum;
import com.cvte.shop.exception.BaseBusinessException;
import com.cvte.shop.mapper.UniversalTableConfigMapper;
import com.cvte.shop.service.UniversalMethodResultService;
import com.cvte.shop.service.UniversalResultFieldsService;
import com.cvte.shop.util.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.cvte.csb.jdbc.mybatis.biz.BaseBiz;
import com.cvte.shop.mapper.UniversalResultFieldsMapper;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 服务实现类
 *
 * @author inv
 * @since 2020-08-04
 */
@Service
@Transactional
public class UniversalResultFieldsServiceImpl extends BaseBiz<UniversalResultFieldsMapper, UniversalResultFields> implements UniversalResultFieldsService {


    @Autowired
    private UniversalResultFieldsMapper universalResultFieldsMapper;

    @Autowired
    private UniversalTableConfigMapper universalTableConfigMapper;

    @Autowired
    private UniversalMethodResultService universalMethodResultService;


    private void checkSql(String sqlContext){
        universalResultFieldsMapper.checkSql(sqlContext);
    }


    @Override
    public void batchInsertFields(List<UniversalResultFields> list, String tableId, String viewId) {
        //批量插入进字段表
        for (UniversalResultFields tableField : list) {
            tableField.setFieldId(UUIDUtil.getUUID());
            tableField.setTableId(tableId);
            tableField.setFieldStatus(UniversalResultFieldsConstants.UN_USE);
            tableField.setViewId(viewId);
            universalResultFieldsMapper.insert(tableField);
        }
    }

    @Override
    public List<UniversalResultFields> tranfserToFields(List<FieldDTO> fieldDTOList) {
        List<UniversalResultFields> resultFields = new ArrayList<>();
        for (FieldDTO fieldDTO : fieldDTOList) {
            UniversalResultFields universalResultFields = new UniversalResultFields(fieldDTO);
            resultFields.add(universalResultFields);
        }
        return resultFields;
    }
}
